Note: This tutorial assumes that you have completed the previous tutorials: Getting started, Pattern creation.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Iterating patterns

Description: This tutorial covers iterating through patterns; a key feature of pattern_manager.

Tutorial Level: BEGINNER

Next Tutorial: Importing and exporting

A key feature of the pattern_manager node is choosing which patterns to set as active and then iterating over these patterns. Setting a pattern (or transform) as active simply means that it is added to the list of transforms which are to be iterated.

Activating transforms

This first that is needed for setting up iteration through our patterns, is choosing which patterns should be part of the iteration. This is done by selectively activating transforms to be included. When activating a transform all successor transforms are also activated. This enables easy activation of patterns of transforms and/or groups of patterns.

Activating a transform is done by calling the /set_active service on the requested transform, in our case lin1 (from the previous tutorial):

Let us first retrieve the id of the pattern transform:

$ rosservice call /pattern_manager/get_transform_id "name: 'lin1'" 
id: 140718458910248

Now we set the pattern transform active:

$ rosservice call /pattern_manager/set_active "id: 140718458910248    
active: true"

By calling the service /get_active_transforms we can check that the pattern transforms are indeed activated:

$ rosservice call /pattern_manager/get_active_transforms
names_and_ids: 
  - 
    name: "lin1_0"
    id: 140718458910336
  - 
    name: "lin1_1"
    id: 140718458910512
  - 
    name: "lin1_2"
    id: 140718458910688
  - 
    name: "lin1_3"
    id: 140718458910864

If we do not wish lin1_3 to be part of the iteration we can call /set_active on that particular transform:

$ rosservice call /pattern_manager/set_active "id: 140718458910864    
active: false" 

The transform is no longer iterable by pattern_manager.

Setting iteration order

Now that we have a list of active transforms to iterate through we can decide in which order to iterate through them. This can be achieved using the /set_iteration_order service. Say we want to swap lin1_0 and lin1_1 in the the order, we call the service /set_iteration_order with the transform ids in the desired order:

$ rosservice call /pattern_manager/get_children "parent_id: 139680123169616" 
names_and_ids: 
  - 
    name: "lin1_0"
    id: 140718458910512
  - 
    name: "lin1_1"
    id: 140718458910248
  - 
    name: "lin1_2"
    id: 140718458910336
  - 
    name: "lin1_3"
    id: 140718458910688
$ rosservice call /pattern_manager/set_iteration_order "id: 140718458910248
order: [140718458910512, 140718458910336, 140718458910688]"

If we now call /get_active_transforms we see the iteration order has changed (lin1_0 and lin1_1 have switched places).

$ rosservice call /pattern_manager/get_active_transforms
names_and_ids: 
  - 
    name: "lin1_1"
    id: 140718458910512
  - 
    name: "lin1_0"
    id: 140718458910336
  -
    name: "lin1_2"
    id: 140718458910688

We now have the setup we want and it is now just a question of iterating through our active transforms.

Iterating

As long as at least one transform is active, the current active transform can be found using the service /get_current_transform:

$ rosservice call /pattern_manager/get_current_transform 
id: 140718458910512
name: "lin1_1"

Calling /iterate will continue the iteration to the next transform in the iteration order,

$ rosservice call /pattern_manager/iterate

until there are no more active transforms left to iterate, in which case the service will return false. Call /get_current_transform again to verify the iteration has updated properly.

$ rosservice call /pattern_manager/get_current_transform 
id: 140718458910336
name: "lin1_0"

We have now covered basic interaction with the pattern_manager node through CLI service calls. The next tutorial will demonstrate how to import and export the transform tree via .yaml files.

Wiki: pattern_manager/Tutorials/Iterating patterns (last edited 2020-01-20 11:23:45 by Mads)